package vip.web3.admin.sys.dao.biz;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import vip.web3.admin.sys.entity.biz.ARecordEntity;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 分红明细Mapper接口
 * <p>
 * aut-horlilei
 *
 * @date 2024-09-27
 */
@Mapper
public interface ARecordDao extends BaseMapper<ARecordEntity> {


    /**
     * 批量删除分红明细
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    int deleteARecordByIds(Integer[] ids);

    /**
     * Y统计充值流水
     */

    @Select("select ifnull(sum(amount),0) from a_record where type = #{type} and user_id = #{userId} and create_date " +
            ">= #{start}  and create_date < #{end}")
    BigDecimal selectTotalRecord(@Param("userId") Integer userId,
                                 @Param("type") Integer type,
                                 @Param("start") Date start,
                                 @Param("end") Date end);

    @Select("select ifnull(sum(amount),0) from a_record where type = #{type} and user_id = #{userId}")
    BigDecimal selectTotalRecordAmount(@Param("userId") Integer userId,@Param("type") Integer type);


    /**
     * 统计发放奖励得条数
     *
     * @param userId
     * @param type
     * @return
     */

    @Select(" SELECT COUNT(*) FROM a_record WHERE type = #{type} and user_id = #{userId}")
    Integer selectCountIncomeNumRecord(@Param("userId") Integer userId,
                                       @Param("type") Integer type);
}
